<?php


namespace App\Http\Controllers\Admin;
use App\Http\Controllers\BaseController;
use App\Lib\UploadLib;
use App\Models\Config;
use Illuminate\Http\Request;

class ConfigController extends BaseController
{

    public function info(Request $request) {
        $info = Config::where('category', 'setting')->pluck( 'value', 'key');
        return $this->success($info);
    }

    /**
     * 修改
     * @param Request $request
     * @return mixed
     * @throws \Illuminate\Validation\ValidationException
     */
    public function store(Request $request) {
        $this->validate($request, [
//            'commission' => 'required',
//            'discount' => 'required',
//            'rec_cookbook_commission' => 'required',
            'vip_commission' => 'required'
            ]);
        $input = $request->input();


//        $model = Config::where('key', 'commission' )->first();
//        $model->value = $input['commission'];
//        $model->save();
//
//        $model = Config::where('key', 'discount' )->first();
//        $model->value = $input['discount'];
//        $model->save();
//
//        $model = Config::where('key', 'rec_cookbook_commission' )->first();
//        $model->value = $input['rec_cookbook_commission'];
//        $model->save();

        $model = Config::where('key', 'vip_commission' )->first();
        $model->value = $input['vip_commission'];
        $model->save();

        return $this->success([]);
    }

    public function store_daren_amount(Request $request) {
        $this->validate($request, [
            'daren_amount' => 'required'
        ]);
        $input = $request->input();
        $model = Config::where('key', 'daren_amount' )->first();
        $model->value = $input['daren_amount'];
        $model->save();
        return $this->success([]);
    }

}

